/*******************************************************************************
 * This file is part of blueprint4j www.blueprint4j.org.
 * 
 *     blueprint4j is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU Lesser General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 * 
 *     blueprint4j is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU Lesser General Public License for more details.
 * 
 *     You should have received a copy of the GNU Lesser General Public License
 *     along with blueprint4j. If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package blueprint4j.db;

public class FieldGroup implements java.io.Serializable {
	private VectorField fields=new VectorField();
	private String group_name=null;
	private Entity entity = null;
	private boolean readonly=false;
	private String icon=null;

	public FieldGroup(Entity entity) {
		this(null,entity);
	}

	public FieldGroup(String name,Entity entity) {
		this(name,false,null,entity);
	}
	
	public FieldGroup(String name,boolean readonly,Entity entity) {
		this(name,readonly,null,entity);
	}

	public FieldGroup(String name,String icon,Entity entity) {
		this(name,false,icon,entity);
	}
	
	public FieldGroup(String name,boolean readonly,String icon,Entity entity) {
		entity.setFieldGroup(this);
		this.entity= entity;
		this.group_name=name;
		this.icon=icon;
		this.readonly = readonly;
	}

	public Entity getEntity() {
		return entity;
	}
	
	void add(Field field){
		if (!(field instanceof FieldImageLarge)){
			fields.add(field);
		}
	}

	public boolean isReadOnly() {
		return readonly;
	}
	
	public VectorField getFields(){
		return fields;
	}

	public String getName(){
		return group_name;
	}

	public String getIconResource(){
		return icon;
	}

	public boolean equals(Object obj){
		return
		   (
		      obj!=null &&
		      obj instanceof FieldGroup &&
		      group_name.equals(((FieldGroup)obj).group_name)
		   );
	}
}

